
/*code data for asian participants*/

/*code and drop non-asians*/

gen asian=0
recode asian(0=1) if Q1==1
tab asian

drop if asian==0

/*treatments*/

gen foreigner=0
recode foreigner(0=1) if m1==2

tab foreigner

/*mediator*/

**solidarity with PoC

gen pocsolid1=Q21
gen pocsolid=(pocsolid1-1)/4
summ pocsolid

gen pocsolid2=(Q22)
recode pocsolid2(1=5)(2=4)(3=3)(4=2)(5=1)
gen pocsolids=(pocsolid2-1)/4

summ pocsolid pocsolids
polychoric pocsolid pocsolids
gen pocsolidscale=(pocsolid+pocsolids)/2
summ pocsolidscale


**legal immigration

gen supportH1B1=Q24
gen supportH1B=(supportH1B1-1)/4
summ supportH1B

gen legalimg1=Q25
gen legalimg=(legalimg1-1)/4
summ legalimg

polychoric supportH1B1 legalimg

gen legalpol=(supportH1B+legalimg)/2
summ legalpol

**undocumented immigration

gen bpatrol1=Q26
recode bpatrol1(1=5)(2=4)(3=3)(4=2)(5=1)
gen bpatrol=(bpatrol1-1)/4
summ bpatrol

gen pathway1=Q27
gen pathway=(pathway1-1)/4
summ pathway

polychoric bpatrol pathway

gen undocpol=(bpatrol+pathway)/2
summ undocpol

***drop those who failed manipulation check

drop if Q19==2

***N=641 - dropped = sample anaylzed
***for reanalysis of entire sample, skip previous line of code


***mediation analysis

**reported inter-item correlations

polychoric pocsolid pocsolids
polychoric bpatrol pathway
polychoric supportH1B legalimg

**the analyses below were later adjusted for ideology in light of request from Reviewer 2

***1 does treatment affect mediator

reg pocsolidscale foreigner
ttest pocsolidscale, by(foreigner)

***2 does mediator affect each outcome

reg legalpol pocsolidscale
reg undocpol pocsolidscale

***3 does treatment directly affect outcomes

reg legalpol foreigner
reg undocpol foreigner

ttest undoc, by(foreigner)

/*results for table 2*/

/*results are robust to inclusion of liberal ideology in downstream path, per Reviewer 2*/

gen liberal1=Q13
gen liberal=(liberal1-1)/6
summ liberal

pwcorr pocsolidscale liberal, sig

reg legalpol pocsolidscale 
reg legalpol foreign pocsolidscale liberal

reg undocpol pocsolidscale
reg undocpol foreign pocsolidscale liberal


***estimate ACMEs, with liberal ideology as covariate

medeff (regress pocsolidscale foreign)(regress undocpol foreign pocsolidscale liberal), mediate(pocsolidscale) treat(foreign) sims(500) seed(1)
medeff (regress pocsolidscale foreign)(regress legalpol foreign pocsolidscale liberal), mediate(pocsolidscale) treat(foreign) sims(500) seed(1)

***sensitivity analyses

medsens (regress pocsolidscale foreigner) (regress undocpol foreigner pocsolidscale liberal), mediate(pocsolidscale) treat(foreigner) sims(1000) eps(.01) graph level(95)
medsens (regress pocsolidscale foreigner) (regress legalpol foreigner pocsolidscale liberal), mediate(pocsolidscale) treat(foreigner) sims(1000) eps(.01) graph level(95)

***quantities for figure 4 are calculated by hand using the relevant regressions above where policy support is influenced by solidarity

***table SI.4 (be sure taht failed manipulation checks are excluded)

reg pocsolid foreigner
reg pocsolids foreigner

reg pathway pocsolid
reg pathway pocsolids
reg bpatrol pocsolid
reg bpatrol pocsolids
reg supportH1B pocsolid
reg supportH1B pocsolids
reg legalimg pocsolid
reg legalimg pocsolids
